﻿using System;

using BrightSword.Crucible;

using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Tests.BrightSword.Crucible
{
    [TestClass]
    public class ExceptionHelperTests
    {
        [TestMethod]
        public void When_ExceptionExpected_IsThrownWithExpectedMessage()
        {
            Action _action = () => { throw new NotSupportedException("this is cool"); };

            Assert.IsNotNull(_action.ExpectException<NotSupportedException>("this is cool"));
        }

        [TestMethod]
        public void When_ExceptionExpected_IsThrownWithIncorrectMessage()
        {
            try
            {
                Action _action = () => { throw new NotSupportedException("this is not cool"); };

                Assert.IsNull(_action.ExpectException<NotSupportedException>("this is cool"));

                Assert.Fail("No exception thrown when exception expected");
            }
            catch (AssertFailedException)
            {
                // pass
            }
        }

        [TestMethod]
        public void When_ExceptionExpected_DifferentExceptionIsThrown()
        {
            try
            {
                Action _action = () => { throw new ArgumentException("this is cool"); };

                _action.ExpectException<NotSupportedException>("this is not cool");

                Assert.Fail("No exception thrown when exception expected");
            }
            catch (AssertFailedException)
            {
                // pass
            }
        }

        [TestMethod]
        public void When_ExceptionExpected_NoExceptionIsThrown()
        {
            try
            {
                Action _action = () =>
                {
                    /* throw no exception */
                };

                _action.ExpectException<NotSupportedException>("this is not cool");

                Assert.Fail("No exception thrown when exception expected");
            }
            catch (AssertFailedException)
            {
                // pass
            }
        }
    }
}